package com.medi.chats.controller.api.m;

import com.github.pagehelper.PageHelper;
import com.medi.chats.model.McChats;
import com.medi.chats.service.activities.ActivitiesService;
import com.medi.chats.service.chats.ChatsService;
import com.medi.chats.vo.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/m/api")
public class HomeApiController {
    @Autowired
    ChatsService chatsService;
    @Autowired
    ActivitiesService activitiesService;

    /**
     * @Description  微信端首页所有信息的取得
     * @Author        Administrator
     * @Date          2018/10/25 17:17
     * @Return
    */
    @PostMapping("/home")
    private ResultMsg home() {
        ResultMsg rm = new ResultMsg();
        rm.setSuccess();
        // 1.获取活动
        rm.add("activityList", activitiesService.selectActivities());

        // 2.获取十条最新的chats
        PageHelper.startPage(1, 15);
        List<McChats> chatsList = chatsService.selectChatsSortDateDesc();
        rm.add("chatsList", chatsList);
        return rm;
    }

}
